<?php
require_once('db.php');
require_once('utils.php');

session_check();
if(!validUser($userg) || !existsUser($userg))
{
	header("Location: $mainURL/404.php");
}
$page = $_GET['page'];
$page = (int)$page;

if($page < 0)
	$page = 0;
/**
 *  TODO esto se tiene que calcular dinamicamente
 *  con el karma. De todas formas, el maximo de la
 *  base de datos esta en 133
 **/
$ncar = 133;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
  <head>
    <title><?php echo $siteName." / ".$userg; ?></title>
    <link rel="stylesheet" type="text/css" href="css/estilo.css" />
  <link rel="stylesheet" type="text/css" href="css/planet.css" />
  <link rel="icon" href="img/favicon.ico" type="image/vnd.microsoft.icon">
  <link rel="alternate" type="application/rss+xml" title="portada" href="<?php echo $mainURL."/rss2.php?user=".$userg; ?>" />
    <script type="text/javascript" src="js/jquery-1.2.1.min.js"></script>
    <script type="text/javascript" src="js/editor.js"></script>
    <meta http-equiv=content-type content="text/html; charset=UTF-8">
  </head>
  <body>
<?php

show_header("Sweetter 2.0 / $userg");

    if (empty($_GET['todo'])){
        print '<div id="head"><h3><span id="user">'.$userg.'</span> dice:</h3></div>';
    }
    else{
        $all_link = (empty($_GET['all'])) ? '<a href="'.$userURL.$userg.'?todo=1&all=1">Show all TODO</a>' : '<a href="'.$userURL.$userg.'?todo=1">Show only TODO</a>';
        print '<div id="head"><h3><span id="user">TODO para '.$userg.'</span>:</h3></div>'.$all_link;
    }

?>
  <div id="comments">
<?php
    if ($my_user == true && empty($_GET['todo'])) {
?>
<form action="" method="POST">
  <input type="button" id="nuevo" value="nuevo"/>
  <input id="new_comment" class="formOculto" type="text" value="" maxlength="133"></input>
  <div id="hc" class="hide"><?php echo $ncar; ?></div>
  <div id="counter">133</div>
  <input type="submit" id="new" value="send"/>
</form>
<?php
    }
?>
  <div id="comments1">
<?php
  $all = (!empty($_GET['all'])) ? true : false;
  $todo = '';
  if (!empty($_GET['todo'])){
    show_todo_comments($page, $all);
    $todo = '&todo=1';
  }
  else
      show_comments($page);
  print '</div>';
  $next_page = $page+1;
  $prev_page = $page-1;
  print '<div id="older"><a href="'.$userURL.$userg.'?page='.$next_page.$todo.'">older</a></div>';
  if ($page > 0)
    print '<div id="newer"><a href="'.$userURL.$userg.'?page='.$prev_page.$todo.'">newer</a></div>';

  print '</div>';
?>
  <div id="followers">
  <h3>Profile</h3>
  <div id="profile">
  <?php
  $error = show_profile($userg, $user);


  ?>
  </div>

 <h3>Followers</h3>
   <div id="followers1">
<?php $n = show_followers(); ?>
  </div>


</div>
	<?php pie();?>
  </body>
</html>

